Code coverage report for ./vidbg.js

Statements: 100% (16 / 16)      Branches: 100% (4 / 4)      Functions: 100% (1 / 1)      Lines: 100% (16 / 16)      Ignored: none     

All files » ./ » vidbg.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47            1 11     11   1       10     10     10 10 10       10     10   1       10   10     10     10  
/**
 * @file vidbg is a 0.3kb micro-library for embedding video backgrounds into web pages.
 * Scaffolded with generator-microjs v0.0.12
 * @author Daniel Lamb <dlamb.open.source@gmail.com>
 */
 
function vidbg(element, sources, overlay) {
  var container, item, html = [], index = sources.length;
 
  // check if the device supports HTML5 video
  if (!document.createElement('video').canPlayType) {
    // not supported
    return;
  }
 
  // start video tag
  html.push('<video autoplay="true" loop="loop" muted="muted" volume="0">');
 
  // order matters in some browsers
  sources.reverse();
 
  // build video tag source(s) html
  while(index--) {
    item = sources[index];
    html.push('<source src="', item.src, '" type="video/', item.type, '" />');
  }
 
  // end video tag
  html.push('</video>');
 
  // check for optional overlay element
  if (overlay) {
    // append optional overlay element
    html.push('<div class="vidbg-overlay"></div>');
  }
 
  // create video DOM element
  container = document.createElement('div');
 
  container.setAttribute('class', 'vidbg');
 
  // set the container HTML
  container.innerHTML = html.join('');
 
  // append container to the provided element
  element.appendChild(container);
}